package com.data.modules.online.cgform.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.data.common.api.vo.Result;
import com.data.common.bpm.api.IBpmBaseExtAPI;
import com.data.common.constant.CommonConstant;
import com.data.common.constant.enums.CgformEnum;
import com.data.common.exception.BootException;
import com.data.common.system.util.JwtUtil;
import com.data.common.util.*;
import com.data.modules.online.auth.entity.OnlAuthData;
import com.data.modules.online.auth.entity.OnlAuthPage;
import com.data.modules.online.auth.entity.OnlAuthRelation;
import com.data.modules.online.auth.service.IOnlAuthDataService;
import com.data.modules.online.auth.service.IOnlAuthPageService;
import com.data.modules.online.auth.service.IOnlAuthRelationService;
import com.data.modules.online.cgform.enhance.CgformEnhanceJavaInter;
import com.data.modules.online.cgform.enhance.CgformEnhanceJavaListInter;
import com.data.modules.online.cgform.enhance.impl.http.CgformEnhanceHttpFormImpl;
import com.data.modules.online.cgform.enhance.impl.http.CgformEnhanceHttpListImpl;
import com.data.modules.online.cgform.entity.*;
import com.data.modules.online.cgform.enums.CgformConstant;
import com.data.modules.online.cgform.mapper.*;
import com.data.modules.online.cgform.model.OnlCgformModel;
import com.data.modules.online.cgform.model.OnlGenerateModel;
import com.data.modules.online.cgform.extend.ExtendJsonKey;
import com.data.modules.online.cgform.service.IOnlCgformFieldService;
import com.data.modules.online.cgform.service.IOnlCgformHeadService;
import com.data.modules.online.cgform.service.IOnlCgformIndexService;
import com.data.modules.online.cgform.util.CgformUtil;
import com.data.modules.online.cgform.util.OnlFormShowType;
import com.data.modules.online.config.exception.BusinessException;
import com.data.modules.online.config.exception.DBException;
import com.data.modules.online.config.datasourceConfig.CgformConfigModel;
import com.data.modules.online.config.datasourceConfig.DataBaseConfig;
import com.data.modules.online.config.datasourceConfig.DmDataBaseConfig;
import com.data.modules.online.config.executor.DataBaseConst;
import com.data.modules.online.config.executor.DbTableProcess;
import com.data.modules.online.config.executor.DbTableUtil;
import com.data.modules.online.config.service.DbTableHandleI;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.HibernateException;
import com.data.codegenerate.database.DbReadTableUtil;
import com.data.codegenerate.generate.impl.CodeGenerateOne;
import com.data.codegenerate.generate.impl.CodeGenerateOneToMany;
import com.data.codegenerate.generate.pojo.ColumnVo;
import com.data.codegenerate.generate.pojo.TableVo;
import com.data.codegenerate.generate.pojo.onetomany.MainTableVo;
import com.data.codegenerate.generate.pojo.onetomany.SubTableVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@SuppressWarnings("ALL")
@Service
public class OnlCgformHeadServiceImpl extends ServiceImpl<OnlCgformHeadMapper, OnlCgformHead> implements IOnlCgformHeadService {

    private static final Logger f213a = LoggerFactory.getLogger(OnlCgformHeadServiceImpl.class);
    @Autowired
    @Lazy
    private IBpmBaseExtAPI bpmBaseExtAPI;
    @Autowired
    private CgformEnhanceHttpFormImpl cgformEnhanceJavaHttp;
    @Autowired
    private CgformEnhanceHttpListImpl cgformEnhanceJavaListHttp;
    @Autowired
    private DataBaseConfig dataBaseConfig;
    @Autowired
    private IOnlCgformFieldService fieldService;
    @Autowired
    private IOnlCgformIndexService indexService;
    @Autowired
    private IOnlAuthDataService onlAuthDataService;
    @Autowired
    private IOnlAuthPageService onlAuthPageService;
    @Autowired
    private IOnlAuthRelationService onlAuthRelationService;
    @Autowired
    private OnlCgformButtonMapper onlCgformButtonMapper;
    @Autowired
    private OnlCgformEnhanceJavaMapper onlCgformEnhanceJavaMapper;
    @Autowired
    private OnlCgformEnhanceJsMapper onlCgformEnhanceJsMapper;
    @Autowired
    private OnlCgformEnhanceSqlMapper onlCgformEnhanceSqlMapper;
    @Autowired
    private IOnlCgformFieldService onlCgformFieldService;
    @Value("${databoot.online.datasource:}")
    private String onlineDatasource;

    private static /* synthetic */ java.lang.Object m158a(java.lang.invoke.SerializedLambda r4) {
        /*
        // Method dump skipped, instructions count: 5842
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.m158a(java.lang.invoke.SerializedLambda):java.lang.Object");
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public Result<?> addAll(OnlCgformModel model) {
        String replace = UUID.randomUUID().toString().replace("-", "");
        OnlCgformHead head = model.getHead();
        List<OnlCgformField> fields = model.getFields();
        List<OnlCgformIndex> indexs = model.getIndexs();
        head.setId(replace);
        for (int i = 0; i < fields.size(); i++) {
            OnlCgformField onlCgformField = fields.get(i);
            onlCgformField.setId(null);
            onlCgformField.setCgformHeadId(replace);
            if (onlCgformField.getOrderNum() == null) {
                onlCgformField.setOrderNum(Integer.valueOf(i));
            }
            m166a(onlCgformField);
        }
        for (OnlCgformIndex onlCgformIndex : indexs) {
            onlCgformIndex.setId(null);
            onlCgformIndex.setCgformHeadId(replace);
        }
        head.setIsDbSynch("N");
        head.setQueryMode(CgformUtil.f232F);
        head.setTableVersion(1);
        head.setCopyType(0);
        if (head.getTableType().intValue() == 3 && head.getTabOrderNum() == null) {
            head.setTabOrderNum(1);
        }
        OnlCgformHeadServiceImpl.super.save(head);
        this.fieldService.saveBatch(fields);
        this.indexService.saveBatch(indexs);
        m169a(head, fields);
        return Result.ok("添加成功");
    }

    @Override
    @org.springframework.transaction.annotation.Transactional(rollbackFor = {java.lang.Exception.class})
    public Result<?> editAll(com.data.modules.online.cgform.model.OnlCgformModel model) {
        OnlCgformHead var2 = model.getHead();
        OnlCgformHead var3 = (OnlCgformHead)super.getById(var2.getId());
        if (var3 == null) {
            return Result.error("未找到对应实体");
        } else {
            String var4 = var3.getIsDbSynch();
            if (CgformUtil.m259a(var3, var2)) {
                var4 = "N";
            }

            Integer var5 = var3.getTableVersion();
            if (var5 == null) {
                var5 = 1;
            }

            var2.setTableVersion(var5 + 1);
            List var6 = model.getFields();
            List<OnlCgformIndex> var7 = model.getIndexs();
            ArrayList var8 = new ArrayList();
            ArrayList var9 = new ArrayList();
            Iterator var10 = var6.iterator();

            while(var10.hasNext()) {
                OnlCgformField var11 = (OnlCgformField)var10.next();
                String var12 = String.valueOf(var11.getId());
                this.a(var11);
                if (var12.length() == 32) {
                    var9.add(var11);
                } else {
                    String var13 = "_pk";
                    if (!var13.equals(var12)) {
                        var11.setId((String)null);
                        var11.setCgformHeadId(var2.getId());
                        var8.add(var11);
                    }
                }
            }

            if (var8.size() > 0) {
                var4 = "N";
            }

            int var18 = 0;

            UpdateWrapper<OnlCgformField> var15;
            Iterator var19;
            OnlCgformField var21;
            for(var19 = var9.iterator(); var19.hasNext(); this.fieldService.update(var21, var15)) {
                var21 = (OnlCgformField)var19.next();
                OnlCgformField var23 = (OnlCgformField)this.fieldService.getById(var21.getId());
                this.a(var23.getMainTable(), var2.getTableName());
                boolean var14 = CgformUtil.m257a(var23, var21);
                if (var14) {
                    var4 = "N";
                }

                if ((var23.getOrderNum() == null ? 0 : var23.getOrderNum()) > var18) {
                    var18 = var23.getOrderNum();
                }

                if ("Y".equals(var3.getIsDbSynch()) && !var21.getDbFieldName().equals(var23.getDbFieldName())) {
                    var21.setDbFieldNameOld(var23.getDbFieldName());
                }

                var15 = new UpdateWrapper();
                var15.lambda().eq(OnlCgformField::getId, var21.getId());
                if (var21.getFieldValidType() == null) {
                    var15.lambda().set(OnlCgformField::getFieldValidType, "");
                }
            }

            for(var19 = var8.iterator(); var19.hasNext(); this.fieldService.save(var21)) {
                var21 = (OnlCgformField)var19.next();
                if (var21.getOrderNum() == null) {
                    ++var18;
                    var21.setOrderNum(var18);
                }
            }

            List var20 = this.indexService.getCgformIndexsByCgformId(var2.getId());
            ArrayList var22 = new ArrayList();
            ArrayList var24 = new ArrayList();
            Iterator var25 = var7.iterator();

            String var16;
            OnlCgformIndex var26;
            while(var25.hasNext()) {
                var26 = (OnlCgformIndex)var25.next();
                var16 = String.valueOf(var26.getId());
                if (var16.length() == 32) {
                    var24.add(var26);
                } else {
                    var26.setId((String)null);
                    var26.setIsDbSynch("N");
                    var26.setDelFlag(CommonConstant.DEL_FLAG_0);
                    var26.setCgformHeadId(var2.getId());
                    var22.add(var26);
                }
            }

            var25 = var20.iterator();

            while(var25.hasNext()) {
                var26 = (OnlCgformIndex)var25.next();
                OnlCgformIndex finalVar2 = var26;
                boolean var28 = var7.stream().anyMatch((var1) -> {
                    return finalVar2.getId().equals(var1.getId());
                });
                if (!var28) {
                    var26.setDelFlag(CommonConstant.DEL_FLAG_1);
                    var24.add(var26);
                    var4 = "N";
                }
            }

            if (var22.size() > 0) {
                var4 = "N";
                this.indexService.saveBatch(var22);
            }

            for(var25 = var24.iterator(); var25.hasNext(); this.indexService.updateById(var26)) {
                var26 = (OnlCgformIndex)var25.next();
                OnlCgformIndex var30 = (OnlCgformIndex)this.indexService.getById(var26.getId());
                boolean var17 = CgformUtil.m260a(var30, var26);
                if (var17) {
                    var4 = "N";
                    var26.setIsDbSynch("N");
                }
            }

            if (model.getDeleteFieldIds().size() > 0) {
                var4 = "N";
                List var27 = model.getDeleteFieldIds();
                Iterator var29 = var27.iterator();

                while(var29.hasNext()) {
                    var16 = (String)var29.next();
                    OnlCgformField var31 = (OnlCgformField)this.fieldService.getById(var16);
                    if (var31 != null) {
                        this.a(var31.getMainTable(), var2.getTableName());
                        this.fieldService.removeById(var16);
                    }
                }
            }

            var2.setIsDbSynch(var4);
            super.updateById(var2);
            this.a(var2, var6);
            this.b(var2, var6);
            return Result.ok("全部修改成功");
        }
    }

    private void b(OnlCgformHead var1, List<OnlCgformField> var2) {
        List var3 = this.list((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getPhysicId, var1.getId()));
        if (var3 != null && var3.size() > 0) {
            Iterator var4 = var3.iterator();

            while(true) {
                List var6;
                String var13;
                ArrayList var19;
                Iterator var22;
                label108:
                do {
                    while(var4.hasNext()) {
                        OnlCgformHead var5 = (OnlCgformHead)var4.next();
                        var6 = this.fieldService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var5.getId()));
                        OnlCgformField var9;
                        if (var6 != null && var6.size() != 0) {
                            HashMap var15 = new HashMap();
                            Iterator var16 = var6.iterator();

                            while(var16.hasNext()) {
                                var9 = (OnlCgformField)var16.next();
                                var15.put(var9.getDbFieldName(), 1);
                            }

                            HashMap var17 = new HashMap();
                            Iterator var18 = var2.iterator();

                            while(var18.hasNext()) {
                                OnlCgformField var10 = (OnlCgformField)var18.next();
                                var17.put(var10.getDbFieldName(), 1);
                            }

                            var19 = new ArrayList();
                            ArrayList var20 = new ArrayList();
                            Iterator var11 = var17.keySet().iterator();

                            while(var11.hasNext()) {
                                String var12 = (String)var11.next();
                                if (var15.get(var12) == null) {
                                    var20.add(var12);
                                } else {
                                    var19.add(var12);
                                }
                            }

                            ArrayList var21 = new ArrayList();
                            var22 = var15.keySet().iterator();

                            while(var22.hasNext()) {
                                var13 = (String)var22.next();
                                if (var17.get(var13) == null) {
                                    var21.add(var13);
                                }
                            }

                            OnlCgformField var23;
                            if (var21.size() > 0) {
                                var22 = var6.iterator();

                                while(var22.hasNext()) {
                                    var23 = (OnlCgformField)var22.next();
                                    if (var21.contains(var23.getDbFieldName())) {
                                        this.fieldService.removeById(var23.getId());
                                    }
                                }
                            }

                            if (var20.size() > 0) {
                                var22 = var2.iterator();

                                while(var22.hasNext()) {
                                    var23 = (OnlCgformField)var22.next();
                                    if (var20.contains(var23.getDbFieldName())) {
                                        OnlCgformField var14 = new OnlCgformField();
                                        var14.setCgformHeadId(var5.getId());
                                        this.a(var23, var14);
                                        this.fieldService.save(var14);
                                    }
                                }
                            }
                            continue label108;
                        }

                        Iterator var7 = var2.iterator();

                        while(var7.hasNext()) {
                            OnlCgformField var8 = (OnlCgformField)var7.next();
                            var9 = new OnlCgformField();
                            var9.setCgformHeadId(var5.getId());
                            this.a(var8, var9);
                            this.fieldService.save(var9);
                        }
                    }

                    return;
                } while(var19.size() <= 0);

                var22 = var19.iterator();

                while(var22.hasNext()) {
                    var13 = (String)var22.next();
                    this.b(var13, var2, var6);
                }
            }
        }
    }

    private void b(String var1, List<OnlCgformField> var2, List<OnlCgformField> var3) {
        OnlCgformField var4 = null;
        Iterator var5 = var2.iterator();

        while(var5.hasNext()) {
            OnlCgformField var6 = (OnlCgformField)var5.next();
            if (var1.equals(var6.getDbFieldName())) {
                var4 = var6;
            }
        }

        OnlCgformField var8 = null;
        Iterator var9 = var3.iterator();

        while(var9.hasNext()) {
            OnlCgformField var7 = (OnlCgformField)var9.next();
            if (var1.equals(var7.getDbFieldName())) {
                var8 = var7;
            }
        }

        if (var4 != null && var8 != null) {
            boolean var10 = false;
            if (!var4.getDbType().equals(var8.getDbType())) {
                var8.setDbType(var4.getDbType());
                var10 = true;
            }

            if (!var4.getDbDefaultVal().equals(var8.getDbDefaultVal())) {
                var8.setDbDefaultVal(var4.getDbDefaultVal());
                var10 = true;
            }

            if (var4.getDbLength() != var8.getDbLength()) {
                var8.setDbLength(var4.getDbLength());
                var10 = true;
            }

            if (var4.getDbIsNull() != var8.getDbIsNull()) {
                var8.setDbIsNull(var4.getDbIsNull());
                var10 = true;
            }

            if (var10) {
                this.fieldService.updateById(var8);
            }
        }

    }

    private void a(OnlCgformHead var1, List<OnlCgformField> var2) {
        if (var1.getTableType() == 3) {
            var1 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectById(var1.getId());

            for(int var3 = 0; var3 < var2.size(); ++var3) {
                OnlCgformField var4 = (OnlCgformField)var2.get(var3);
                String var5 = var4.getMainTable();
                if (!ConvertUtils.isEmpty(var5)) {
                    OnlCgformHead var6 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var5));
                    if (var6 != null) {
                        String var7 = var6.getSubTableStr();
                        if (ConvertUtils.isEmpty(var7)) {
                            var7 = var1.getTableName();
                        } else if (var7.indexOf(var1.getTableName()) < 0) {
                            ArrayList var8 = new ArrayList(Arrays.asList(var7.split(",")));

                            for(int var9 = 0; var9 < var8.size(); ++var9) {
                                String var10 = (String)var8.get(var9);
                                OnlCgformHead var11 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var10));
                                if (var11 != null && var1.getTabOrderNum() < ConvertUtils.getInt(var11.getTabOrderNum(), 0)) {
                                    var8.add(var9, var1.getTableName());
                                    break;
                                }
                            }

                            if (var8.indexOf(var1.getTableName()) < 0) {
                                var8.add(var1.getTableName());
                            }

                            var7 = String.join(",", var8);
                        }

                        var6.setSubTableStr(var7);
                        ((OnlCgformHeadMapper)this.baseMapper).updateById(var6);
                        break;
                    }
                }
            }
        } else {
            List var12 = ((OnlCgformHeadMapper)this.baseMapper).selectList((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).like(OnlCgformHead::getSubTableStr, var1.getTableName()));
            if (var12 != null && var12.size() > 0) {
                Iterator var13 = var12.iterator();

                while(var13.hasNext()) {
                    OnlCgformHead var14 = (OnlCgformHead)var13.next();
                    String var15 = var14.getSubTableStr();
                    if (var14.getSubTableStr().equals(var1.getTableName())) {
                        var15 = "";
                    } else if (var14.getSubTableStr().startsWith(var1.getTableName() + ",")) {
                        var15 = var15.replace(var1.getTableName() + ",", "");
                    } else if (var14.getSubTableStr().endsWith("," + var1.getTableName())) {
                        var15 = var15.replace("," + var1.getTableName(), "");
                    } else if (var14.getSubTableStr().indexOf("," + var1.getTableName() + ",") != -1) {
                        var15 = var15.replace("," + var1.getTableName() + ",", ",");
                    }

                    var14.setSubTableStr(var15);
                    ((OnlCgformHeadMapper)this.baseMapper).updateById(var14);
                }
            }
        }

    }

    private void a(OnlCgformField var1) {
        if ("Text".equals(var1.getDbType()) || "Blob".equals(var1.getDbType())) {
            var1.setDbLength(0);
            var1.setDbPointLength(0);
        }

    }

    private void a(String var1, String var2) {
        if (ConvertUtils.isNotEmpty(var1)) {
            LambdaQueryWrapper var3 = (LambdaQueryWrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var1);
            OnlCgformHead var4 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne(var3);
            if (var4 != null && ConvertUtils.isNotEmpty(var4.getSubTableStr())) {
                String var5 = var4.getSubTableStr();
                String[] var6 = var5.split(",");
                ArrayList var7 = new ArrayList();
                String[] var8 = var6;
                int var9 = var6.length;

                for(int var10 = 0; var10 < var9; ++var10) {
                    String var11 = var8[var10];
                    if (!var11.equals(var2)) {
                        var7.add(var11);
                    }
                }

                var4.setSubTableStr(String.join(",", var7));
                ((OnlCgformHeadMapper)this.baseMapper).updateById(var4);
            }
        }

    }

private void m165a(java.lang.String r8, java.lang.String r9) {
        /*
            r7 = this;
            boolean r0 = org.jeecg.common.util.ConvertUtils.isNotEmpty(r8)
            if (r0 == 0) goto L_0x005d
            com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper r0 = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
            void r1 = r0.<init>()
            java.lang.Object r0 = r0.eq(r1, r8)
            com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper r0 = (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) r0
            com.baomidou.mybatisplus.core.mapper.BaseMapper r1 = r7.baseMapper
            com.data.modules.online.cgform.mapper.OnlCgformHeadMapper r1 = (com.data.modules.online.cgform.mapper.OnlCgformHeadMapper) r1
            java.lang.Object r0 = r1.selectOne(r0)
            com.data.modules.online.cgform.entity.OnlCgformHead r0 = (com.data.modules.online.cgform.entity.OnlCgformHead) r0
            if (r0 == 0) goto L_0x005d
            java.lang.String r1 = r0.getSubTableStr()
            boolean r1 = org.jeecg.common.util.ConvertUtils.isNotEmpty(r1)
            if (r1 == 0) goto L_0x005d
            java.lang.String r1 = r0.getSubTableStr()
            java.lang.String r2 = ","
            java.lang.String[] r2 = r1.split(r2)
            java.util.ArrayList r3 = new java.util.ArrayList
            r3.<init>()
            int r4 = r2.length
            r1 = 0
        L_0x003c:
            if (r1 >= r4) goto L_0x004d
            r5 = r2[r1]
            boolean r6 = r5.equals(r9)
            if (r6 == 0) goto L_0x0049
        L_0x0046:
            int r1 = r1 + 1
            goto L_0x003c
        L_0x0049:
            r3.add(r5)
            goto L_0x0046
        L_0x004d:
            java.lang.String r1 = ","
            java.lang.String r1 = java.lang.String.join(r1, r3)
            r0.setSubTableStr(r1)
            com.baomidou.mybatisplus.core.mapper.BaseMapper r1 = r7.baseMapper
            com.data.modules.online.cgform.mapper.OnlCgformHeadMapper r1 = (com.data.modules.online.cgform.mapper.OnlCgformHeadMapper) r1
            r1.updateById(r0)
        L_0x005d:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.m165a(java.lang.String, java.lang.String):void");
    }


    @Override
    public void doDbSynch(String code, String synMethod) throws HibernateException, IOException, TemplateException, SQLException, DBException {
        OnlCgformHead var3 = (OnlCgformHead)this.getById(code);
        if (var3 == null) {
            throw new DBException("实体配置不存在");
        } else {
            String var4 = var3.getTableName();
            LambdaQueryWrapper<OnlCgformField> var5 = new LambdaQueryWrapper();
            var5.eq(OnlCgformField::getCgformHeadId, code);
            var5.orderByAsc(OnlCgformField::getOrderNum);
            List var6 = this.fieldService.list(var5);
            CgformConfigModel var7 = new CgformConfigModel();
            var7.setTableName(var4);
            var7.setJformPkType(var3.getIdType());
            var7.setJformPkSequence(var3.getIdSequence());
            var7.setContent(var3.getTableTxt());
            var7.setColumns(var6);
            DataBaseConfig var8 = this.getOnlineDataBaseConfig();
            var7.setDbConfig(var8);
            DbType var9 = DbTableUtil.getDbType(var8);
            if ("normal".equals(synMethod) && !var9.equals(DbType.SQLITE)) {
                long var22 = System.currentTimeMillis();
                boolean var12 = DbTableUtil.checkTableIsExist(var4, var8);
                if (var12) {
                    DbTableProcess var13 = new DbTableProcess(var8);
                    List var14 = var13.getAlterTableStringList(var7);
                    Iterator var15 = var14.iterator();

                    while(var15.hasNext()) {
                        String var16 = (String)var15.next();
                        if (!ConvertUtils.isEmpty(var16) && !ConvertUtils.isEmpty(var16.trim())) {
                            ((OnlCgformHeadMapper)this.baseMapper).executeDDL(var16);
                        }
                    }

                    List var23 = this.indexService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformIndex>()).eq(OnlCgformIndex::getCgformHeadId, code));
                    Iterator var24 = var23.iterator();

                    label63:
                    while(true) {
                        OnlCgformIndex var17;
                        do {
                            if (!var24.hasNext()) {
                                break label63;
                            }

                            var17 = (OnlCgformIndex)var24.next();
                        } while(!"N".equals(var17.getIsDbSynch()) && !CommonConstant.DEL_FLAG_1.equals(var17.getDelFlag()));

                        String var18 = var13.countIndex(var17.getIndexName(), var4);
                        if (this.indexService.isExistIndex(var18)) {
                            String var19 = var13.countIndex(var17.getIndexName(), var4);

                            try {
                                ((OnlCgformHeadMapper)this.baseMapper).executeDDL(var19);
                                if (CommonConstant.DEL_FLAG_1.equals(var17.getDelFlag())) {
                                    this.indexService.removeById(var17.getId());
                                }
                            } catch (Exception var21) {
                                log.error("删除表【" + var4 + "】索引(" + var17.getIndexName() + ")失败!", var21);
                            }
                        } else if (CommonConstant.DEL_FLAG_1.equals(var17.getDelFlag())) {
                            this.indexService.removeById(var17.getId());
                        }
                    }
                } else {
                    DbTableProcess.m416a(var7);
                }
            } else if ("force".equals(synMethod) || var9.equals(DbType.SQLITE)) {
                DbTableHandleI var10 = DbTableUtil.getTableHandle();
                String var11 = var10.dropTableSQL(var4);
                ((OnlCgformHeadMapper)this.baseMapper).executeDDL(var11);
                DbTableProcess.m416a(var7);
            }

            this.indexService.createIndex(code, DbTableUtil.getDatabaseType(), var4);
            var3.setIsDbSynch("Y");
            if (var3.getTableVersion() == 1) {
                var3.setTableVersion(2);
            }

            this.updateById(var3);
        }
    }

    @Override
    public void deleteRecordAndTable(String id) throws DBException, SQLException {
        OnlCgformHead onlCgformHead = (OnlCgformHead) getById(id);
        if (onlCgformHead == null) {
            throw new DBException("实体配置不存在");
        }
        System.currentTimeMillis();
        if (DbTableUtil.checkTableIsExist(onlCgformHead.getTableName()).booleanValue()) {
            this.baseMapper.executeDDL(DbTableUtil.getTableHandle().dropTableSQL(onlCgformHead.getTableName()));
        }
        this.baseMapper.deleteById(id);
        m168a(onlCgformHead);
    }

    @Override
    public void deleteRecord(String id) throws DBException, SQLException {
        OnlCgformHead var2 = (OnlCgformHead)this.getById(id);
        if (var2 == null) {
            throw new DBException("实体配置不存在");
        } else {
            this.a(id);
            LambdaQueryWrapper<OnlCgformHead> var3 = new LambdaQueryWrapper<OnlCgformHead>();
            var3.eq(OnlCgformHead::getPhysicId, id);
            List var4 = ((OnlCgformHeadMapper)this.baseMapper).selectList(var3);
            if (var4 != null && var4.size() > 0) {
                Iterator var5 = var4.iterator();

                while(var5.hasNext()) {
                    OnlCgformHead var6 = (OnlCgformHead)var5.next();
                    this.a(var6.getId());
                }
            }

            this.m168a(var2);
        }
    }

    private void a(String var1) {
        ((OnlCgformHeadMapper)this.baseMapper).deleteById(var1);
        LambdaQueryWrapper<OnlCgformField> var2 = new LambdaQueryWrapper<OnlCgformField>();
        var2.eq(OnlCgformField::getCgformHeadId, var1);
        this.fieldService.remove(var2);
        LambdaQueryWrapper<OnlAuthRelation> var3 = new LambdaQueryWrapper<OnlAuthRelation>();
        var3.eq(OnlAuthRelation::getCgformId, var1);
        this.onlAuthRelationService.remove(var3);
        LambdaQueryWrapper<OnlAuthData> var4 = new LambdaQueryWrapper<OnlAuthData>();
        var4.eq(OnlAuthData::getCgformId, var1);
        this.onlAuthDataService.remove(var4);
        LambdaQueryWrapper<OnlAuthPage> var5 = new LambdaQueryWrapper<OnlAuthPage>();
        var5.eq(OnlAuthPage::getCgformId, var1);
        this.onlAuthPageService.remove(var5);
    }

    private void m168a(OnlCgformHead var1) {
        if (var1.getTableType() == 3) {
            LambdaQueryWrapper var2 = (LambdaQueryWrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var1.getId());
            List var3 = this.fieldService.list(var2);
            String var4 = null;
            Iterator var5 = var3.iterator();

            while(var5.hasNext()) {
                OnlCgformField var6 = (OnlCgformField)var5.next();
                var4 = var6.getMainTable();
                if (ConvertUtils.isNotEmpty(var4)) {
                    break;
                }
            }

            if (ConvertUtils.isNotEmpty(var4)) {
                OnlCgformHead var8 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var4));
                if (var8 != null) {
                    String var9 = var8.getSubTableStr();
                    if (ConvertUtils.isNotEmpty(var9)) {
                        List var7 = (List)Arrays.asList(var9.split(",")).stream().collect(Collectors.toList());
                        var7.remove(var1.getTableName());
                        var8.setSubTableStr(String.join(",", var7));
                        ((OnlCgformHeadMapper)this.baseMapper).updateById(var8);
                    }
                }
            }
        }

    }

    @Override
    public List<Map<String, Object>> queryListData(String sql) {
        return this.baseMapper.queryList(sql);
    }

    @Override
    public void saveEnhance(OnlCgformEnhanceJs onlCgformEnhanceJs) {
        this.onlCgformEnhanceJsMapper.insert(onlCgformEnhanceJs);
    }

    @Override
    public com.data.modules.online.cgform.entity.OnlCgformEnhanceJs queryEnhance(String code, String type) {
        return (OnlCgformEnhanceJs)this.onlCgformEnhanceJsMapper.selectOne(new LambdaQueryWrapper<OnlCgformEnhanceJs>().eq(OnlCgformEnhanceJs::getCgJsType, type).eq(OnlCgformEnhanceJs::getCgformHeadId, code));
    }

    @Override
    public void editEnhance(OnlCgformEnhanceJs onlCgformEnhanceJs) {
        this.onlCgformEnhanceJsMapper.updateById(onlCgformEnhanceJs);
    }

    @Override
    public com.data.modules.online.cgform.entity.OnlCgformEnhanceSql queryEnhanceSql(String formId, String buttonCode) {
        return (OnlCgformEnhanceSql)this.onlCgformEnhanceSqlMapper.selectOne((new LambdaQueryWrapper<OnlCgformEnhanceSql>()).eq(OnlCgformEnhanceSql::getCgformHeadId, formId).eq(OnlCgformEnhanceSql::getButtonCode, buttonCode));
    }

    @Override
    public com.data.modules.online.cgform.entity.OnlCgformEnhanceJava queryEnhanceJava(com.data.modules.online.cgform.entity.OnlCgformEnhanceJava onlCgformEnhanceJava) {
        LambdaQueryWrapper<OnlCgformEnhanceJava> var2 = new LambdaQueryWrapper();
        var2.eq(OnlCgformEnhanceJava::getButtonCode, onlCgformEnhanceJava.getButtonCode());
        var2.eq(OnlCgformEnhanceJava::getCgformHeadId, onlCgformEnhanceJava.getCgformHeadId());
        var2.eq(OnlCgformEnhanceJava::getCgJavaType, onlCgformEnhanceJava.getCgJavaType());
        var2.eq(OnlCgformEnhanceJava::getEvent, onlCgformEnhanceJava.getEvent());
        return (OnlCgformEnhanceJava)this.onlCgformEnhanceJavaMapper.selectOne(var2);
    }

    @Override
    public List<OnlCgformButton> queryButtonList(String code, boolean isListButton) {
        LambdaQueryWrapper<OnlCgformButton> var3 = new LambdaQueryWrapper();
        var3.eq(OnlCgformButton::getButtonStatus, "1");
        var3.eq(OnlCgformButton::getCgformHeadId, code);
        if (isListButton) {
            var3.in(OnlCgformButton::getButtonStyle, new Object[]{"link", "button"});
        } else {
            var3.eq(OnlCgformButton::getButtonStyle, "form");
        }

        var3.orderByAsc(OnlCgformButton::getOrderNum);
        return this.onlCgformButtonMapper.selectList(var3);
    }


// com.data.modules.online.cgform.service.IOnlCgformHeadService

    @Override
    public List<OnlCgformButton> queryButtonList(String code) {
        LambdaQueryWrapper<OnlCgformButton> var2 = new LambdaQueryWrapper();
        var2.eq(OnlCgformButton::getButtonStatus, "1");
        var2.eq(OnlCgformButton::getCgformHeadId, code);
        var2.orderByAsc(com.data.modules.online.cgform.entity.OnlCgformButton::getOrderNum);
        return this.onlCgformButtonMapper.selectList(var2);
    }

    @Override
    public List<String> queryOnlinetables() {
        return this.baseMapper.queryOnlinetables();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void saveDbTable2Online(String tbname) {
        OnlCgformHead onlCgformHead = new OnlCgformHead();
        onlCgformHead.setTableType(1);
        onlCgformHead.setIsCheckbox("Y");
        onlCgformHead.setIsDbSynch("Y");
        onlCgformHead.setIsTree("N");
        onlCgformHead.setIsPage("Y");
        onlCgformHead.setQueryMode("group");
        onlCgformHead.setTableName(tbname.toLowerCase());
        onlCgformHead.setTableTxt(tbname);
        onlCgformHead.setTableVersion(1);
        onlCgformHead.setFormTemplate("1");
        onlCgformHead.setCopyType(0);
        onlCgformHead.setIsDesForm("N");
        onlCgformHead.setScroll(1);
        onlCgformHead.setThemeTemplate(CgformUtil.f237K);
        String generate = UUIDGenerator.generate();
        onlCgformHead.setId(generate);
        ArrayList arrayList = new ArrayList();
        try {
            List readOriginalTableColumn = DbReadTableUtil.readOriginalTableColumn(tbname);
            for (int i = 0; i < readOriginalTableColumn.size(); i++) {
                ColumnVo columnVo = (ColumnVo) readOriginalTableColumn.get(i);
                String fieldDbName = columnVo.getFieldDbName();
                OnlCgformField onlCgformField = new OnlCgformField();
                onlCgformField.setCgformHeadId(generate);
                onlCgformField.setDbFieldNameOld(columnVo.getFieldDbName().toLowerCase());
                onlCgformField.setDbFieldName(columnVo.getFieldDbName().toLowerCase());
                if (ConvertUtils.isNotEmpty(columnVo.getFiledComment())) {
                    onlCgformField.setDbFieldTxt(columnVo.getFiledComment());
                } else {
                    onlCgformField.setDbFieldTxt(columnVo.getFieldName());
                }
                onlCgformField.setDbIsKey(0);
                onlCgformField.setIsShowForm(1);
                onlCgformField.setIsQuery(0);
                onlCgformField.setFieldMustInput("0");
                onlCgformField.setIsShowList(1);
                onlCgformField.setOrderNum(Integer.valueOf(i + 1));
                onlCgformField.setQueryMode(CgformUtil.f232F);
                onlCgformField.setDbLength(Integer.valueOf(ConvertUtils.getInt(columnVo.getPrecision())));
                onlCgformField.setFieldLength(120);
                onlCgformField.setDbPointLength(Integer.valueOf(ConvertUtils.getInt(columnVo.getScale())));
                onlCgformField.setFieldShowType(ExtendJsonKey.f91e);
                onlCgformField.setDbIsNull(Integer.valueOf("Y".equals(columnVo.getNullable()) ? 1 : 0));
                onlCgformField.setIsReadOnly(0);
                if ("id".equalsIgnoreCase(fieldDbName)) {
                    if (Arrays.asList("java.lang.Integer", "java.lang.Long").contains(columnVo.getFieldType())) {
                        onlCgformHead.setIdType("NATIVE");
                    } else {
                        onlCgformHead.setIdType("UUID");
                    }
                    onlCgformField.setDbIsKey(1);
                    onlCgformField.setIsShowForm(0);
                    onlCgformField.setIsShowList(0);
                    onlCgformField.setIsReadOnly(1);
                }
                if ("create_by".equalsIgnoreCase(fieldDbName) || "create_time".equalsIgnoreCase(fieldDbName) || "update_by".equalsIgnoreCase(fieldDbName) || "update_time".equalsIgnoreCase(fieldDbName) || "sys_org_code".equalsIgnoreCase(fieldDbName)) {
                    onlCgformField.setIsShowForm(0);
                    onlCgformField.setIsShowList(0);
                }
                if ("java.lang.Integer".equalsIgnoreCase(columnVo.getFieldType())) {
                    onlCgformField.setDbType("int");
                } else if ("java.lang.Long".equalsIgnoreCase(columnVo.getFieldType())) {
                    onlCgformField.setDbType("int");
                } else if ("java.util.Date".equalsIgnoreCase(columnVo.getFieldType())) {
                    onlCgformField.setDbType("Date");
                    onlCgformField.setFieldShowType(OnlFormShowType.f320d);
                } else if ("java.lang.Double".equalsIgnoreCase(columnVo.getFieldType()) || "java.lang.Float".equalsIgnoreCase(columnVo.getFieldType())) {
                    onlCgformField.setDbType("double");
                } else if ("java.math.BigDecimal".equalsIgnoreCase(columnVo.getFieldType()) || "BigDecimal".equalsIgnoreCase(columnVo.getFieldType())) {
                    onlCgformField.setDbType("BigDecimal");
                } else if ("byte[]".equalsIgnoreCase(columnVo.getFieldType()) || columnVo.getFieldType().contains("blob")) {
                    onlCgformField.setDbType("Blob");
                    columnVo.setCharmaxLength((String) null);
                } else if ("java.lang.Object".equals(columnVo.getFieldType()) && (ExtendJsonKey.f91e.equalsIgnoreCase(columnVo.getFieldDbType()) || "ntext".equalsIgnoreCase(columnVo.getFieldDbType()))) {
                    onlCgformField.setDbType(DataBaseConst.f475j);
                    onlCgformField.setFieldShowType(DataBaseConst.f476k);
                } else if (!"java.lang.Object".equals(columnVo.getFieldType()) || !"image".equalsIgnoreCase(columnVo.getFieldDbType())) {
                    onlCgformField.setDbType(DataBaseConst.f474i);
                } else {
                    onlCgformField.setDbType("Blob");
                }
                if (!ConvertUtils.isEmpty(columnVo.getPrecision()) || !ConvertUtils.isNotEmpty(columnVo.getCharmaxLength())) {
                    if (ConvertUtils.isNotEmpty(columnVo.getPrecision())) {
                        onlCgformField.setDbLength(Integer.valueOf(columnVo.getPrecision()));
                    } else if (onlCgformField.getDbType().equals("int")) {
                        onlCgformField.setDbLength(10);
                    }
                    if (ConvertUtils.isNotEmpty(columnVo.getScale())) {
                        onlCgformField.setDbPointLength(Integer.valueOf(columnVo.getScale()));
                    }
                } else if (Long.valueOf(columnVo.getCharmaxLength()).longValue() >= 3000) {
                    onlCgformField.setDbType(DataBaseConst.f475j);
                    onlCgformField.setFieldShowType(DataBaseConst.f476k);
                    try {
                        onlCgformField.setDbLength(Integer.valueOf(columnVo.getCharmaxLength()));
                    } catch (Exception e) {
                        f213a.error(e.getMessage(), e);
                    }
                } else {
                    onlCgformField.setDbLength(Integer.valueOf(columnVo.getCharmaxLength()));
                }
                if (ConvertUtils.getInt(columnVo.getPrecision()) == -1 && ConvertUtils.getInt(columnVo.getScale()) == 0) {
                    onlCgformField.setDbType(DataBaseConst.f475j);
                }
                if ("Blob".equals(onlCgformField.getDbType()) || DataBaseConst.f475j.equals(onlCgformField.getDbType()) || "Date".equals(onlCgformField.getDbType())) {
                    onlCgformField.setDbLength(0);
                    onlCgformField.setDbPointLength(0);
                }
                arrayList.add(onlCgformField);
            }
        } catch (Exception e2) {
            f213a.error(e2.getMessage(), e2);
        }
        if (ConvertUtils.isEmpty(onlCgformHead.getFormCategory())) {
            onlCgformHead.setFormCategory("bdfl_include");
        }
        save(onlCgformHead);
        this.fieldService.saveBatch(arrayList);
    }


private void m169a(OnlCgformHead var1, List<OnlCgformField> var2) {
        if (var1.getTableType() == 3) {
            var1 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectById(var1.getId());

            for(int var3 = 0; var3 < var2.size(); ++var3) {
                OnlCgformField var4 = (OnlCgformField)var2.get(var3);
                String var5 = var4.getMainTable();
                if (!ConvertUtils.isEmpty(var5)) {
                    OnlCgformHead var6 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var5));
                    if (var6 != null) {
                        String var7 = var6.getSubTableStr();
                        if (ConvertUtils.isEmpty(var7)) {
                            var7 = var1.getTableName();
                        } else if (var7.indexOf(var1.getTableName()) < 0) {
                            ArrayList var8 = new ArrayList(Arrays.asList(var7.split(",")));

                            for(int var9 = 0; var9 < var8.size(); ++var9) {
                                String var10 = (String)var8.get(var9);
                                OnlCgformHead var11 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var10));
                                if (var11 != null && var1.getTabOrderNum() < ConvertUtils.getInt(var11.getTabOrderNum(), 0)) {
                                    var8.add(var9, var1.getTableName());
                                    break;
                                }
                            }

                            if (var8.indexOf(var1.getTableName()) < 0) {
                                var8.add(var1.getTableName());
                            }

                            var7 = String.join(",", var8);
                        }

                        var6.setSubTableStr(var7);
                        ((OnlCgformHeadMapper)this.baseMapper).updateById(var6);
                        break;
                    }
                }
            }
        } else {
            List var12 = ((OnlCgformHeadMapper)this.baseMapper).selectList((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).like(OnlCgformHead::getSubTableStr, var1.getTableName()));
            if (var12 != null && var12.size() > 0) {
                Iterator var13 = var12.iterator();

                while(var13.hasNext()) {
                    OnlCgformHead var14 = (OnlCgformHead)var13.next();
                    String var15 = var14.getSubTableStr();
                    if (var14.getSubTableStr().equals(var1.getTableName())) {
                        var15 = "";
                    } else if (var14.getSubTableStr().startsWith(var1.getTableName() + ",")) {
                        var15 = var15.replace(var1.getTableName() + ",", "");
                    } else if (var14.getSubTableStr().endsWith("," + var1.getTableName())) {
                        var15 = var15.replace("," + var1.getTableName(), "");
                    } else if (var14.getSubTableStr().indexOf("," + var1.getTableName() + ",") != -1) {
                        var15 = var15.replace("," + var1.getTableName() + ",", ",");
                    }

                    var14.setSubTableStr(var15);
                    ((OnlCgformHeadMapper)this.baseMapper).updateById(var14);
                }
            }
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public String saveManyFormData(String code, JSONObject json, String xAccessToken) throws DBException, BusinessException {
        OnlCgformHead var4 = (OnlCgformHead)this.getById(code);
        if (var4 == null) {
            throw new DBException("数据库主表ID[" + code + "]不存在");
        } else {
            String var5 = "add";
            this.executeEnhanceJava(var5, "start", var4, json);
            String var6 = CgformUtil.m285f(var4.getTableName());
            if (var4.getTableType() == 2) {
                String var7 = var4.getSubTableStr();
                if (ConvertUtils.isNotEmpty(var7)) {
                    String[] var8 = var7.split(",");
                    String[] var9 = var8;
                    int var10 = var8.length;

                    for(int var11 = 0; var11 < var10; ++var11) {
                        String var12 = var9[var11];
                        JSONArray var13 = json.getJSONArray(var12);
                        if (var13 != null && var13.size() != 0) {
                            OnlCgformHead var14 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var12));
                            if (var14 != null) {
                                List var15 = this.fieldService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var14.getId()));
                                String var16 = "";
                                String var17 = null;
                                Iterator var18 = var15.iterator();

                                while(var18.hasNext()) {
                                    OnlCgformField var19 = (OnlCgformField)var18.next();
                                    if (!ConvertUtils.isEmpty(var19.getMainField())) {
                                        var16 = var19.getDbFieldName();
                                        String var20 = var19.getMainField();
                                        if (json.get(var20.toLowerCase()) != null) {
                                            var17 = json.getString(var20.toLowerCase());
                                        }

                                        if (json.get(var20.toUpperCase()) != null) {
                                            var17 = json.getString(var20.toUpperCase());
                                        }
                                    }
                                }

                                for(int var22 = 0; var22 < var13.size(); ++var22) {
                                    JSONObject var23 = var13.getJSONObject(var22);
                                    if (var17 != null) {
                                        var23.put(var16, var17);
                                    }

                                    this.fieldService.saveFormData(var15, var12, var23);
                                }
                            }
                        }
                    }
                }
            }

            if ("Y".equals(var4.getIsTree())) {
                this.fieldService.saveTreeFormData(code, var6, json, var4.getTreeIdField(), var4.getTreeParentIdField());
            } else {
                this.fieldService.saveFormData(code, var6, json, false);
            }

            this.executeEnhanceSql(var5, code, json);
            this.executeEnhanceJava(var5, "end", var4, json);

            try {
                this.bpmOp(json, var4.getTableName(), var4.getId());
            } catch (Exception var21) {
                throw new BootException("流程发起失败" + var21.getMessage());
            }

            return var4.getTableName();
        }
    }

    private void bpmOp(JSONObject var1, String var2, String var3) throws Exception {
        if (var1.containsKey("jeecg_submit_form_and_flow") && "1".equals(var1.getString("jeecg_submit_form_and_flow"))) {
            String curUsername = JwtUtil.getUserNameByToken(SpringContextUtils.getHttpServletRequest());
            String flowCode = "onl_" + var2;
            String id = ConvertUtils.getString(var1.getString("id"), var1.getString("ID"));
            this.bpmBaseExtAPI.startMutilProcess(flowCode, id, "modules/bpm/task/form/OnlineFormDetail", "check/onlineForm/detail", curUsername, (String)null);
        } else {
            List var4 = this.fieldService.list((Wrapper)((LambdaQueryWrapper<OnlCgformField>)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var3)).eq(OnlCgformField::getDbFieldName, "bpm_status"));
            if (var4 != null && var4.size() > 0 || ConvertUtils.isNotEmpty(var1.get("bpm_status")) || ConvertUtils.isNotEmpty(var1.get("bpm_status".toUpperCase()))) {
                try {
                    String username = JwtUtil.getUserNameByToken(SpringContextUtils.getHttpServletRequest());
                    Result result = this.bpmBaseExtAPI.saveMutilProcessDraft("onl_" + var2, var1.get("id").toString(), "modules/bpm/task/form/OnlineFormDetail", "check/onlineForm/detail", username, (String)null);
                } catch (Exception e) {
                    log.error("保存流程草稿异常, " + e.getMessage(), e);
                }
            }
        }

    }

    @Override
    public Map<String, Object> querySubFormData(String table, String mainId) throws DBException {
        new HashMap();
        OnlCgformHead var4 = (OnlCgformHead)this.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, table));
        if (var4 == null) {
            throw new DBException("数据库子表[" + table + "]不存在");
        } else {
            List var5 = this.fieldService.queryFormFields(var4.getId(), false);
            String var6 = null;
            Iterator var7 = var5.iterator();

            while(var7.hasNext()) {
                OnlCgformField var8 = (OnlCgformField)var7.next();
                if (ConvertUtils.isNotEmpty(var8.getMainField())) {
                    var6 = var8.getDbFieldName();
                    break;
                }
            }

            List var9 = this.fieldService.querySubFormData(var5, table, var6, mainId);
            if (var9 != null && var9.size() == 0) {
                throw new DBException("数据库子表[" + table + "]未找到相关信息,主表ID为" + mainId);
            } else if (var9.size() > 1) {
                throw new DBException("数据库子表[" + table + "]存在多条记录,主表ID为" + mainId);
            } else {
                Map var3 = (Map)var9.get(0);
                return var3;
            }
        }
    }

    @Override
    public List<Map<String, Object>> queryManySubFormData(String table, String mainId) throws DBException {
        OnlCgformHead var3 = (OnlCgformHead)this.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, table));
        if (var3 == null) {
            throw new DBException("数据库子表[" + table + "]不存在");
        } else {
            List var4 = this.fieldService.queryFormFields(var3.getId(), false);
            if (var4 != null && var4.size() != 0) {
                String var5 = null;
                String var6 = null;
                String var7 = null;
                Iterator var8 = var4.iterator();

                OnlCgformField var9;
                while(var8.hasNext()) {
                    var9 = (OnlCgformField)var8.next();
                    if (ConvertUtils.isNotEmpty(var9.getMainField())) {
                        var5 = var9.getDbFieldName();
                        var6 = var9.getMainTable();
                        var7 = var9.getMainField();
                        break;
                    }
                }

                ArrayList var16 = new ArrayList();
                var9 = new OnlCgformField();
                var9.setDbFieldName(var7);
                var16.add(var9);
                Map var10 = this.fieldService.queryFormData(var16, var6, mainId);
                String var11 = ConvertUtils.getString(ConvertUtils.getString(var10.get(var7)), ConvertUtils.getString(var10.get(var7.toUpperCase())));
                List var12 = this.fieldService.querySubFormData(var4, table, var5, var11);
                if (var12 != null && var12.size() == 0) {
                    throw new DBException("数据库子表[" + table + "]未找到相关信息,主表ID为" + mainId);
                } else {
                    ArrayList var13 = new ArrayList(var12.size());
                    Iterator var14 = var12.iterator();

                    while(var14.hasNext()) {
                        Map var15 = (Map)var14.next();

                        var13.add(CgformUtil.m242a(var15));
                    }

                    return var13;
                }
            } else {
                throw new DBException("找不到子表字段，请确认配置是否正确!");
            }
        }
    }

    @Override
    public Map<String, Object> queryManyFormData(String code, String id) throws DBException {
        OnlCgformHead var3 = (OnlCgformHead)this.getById(code);
        if (var3 == null) {
            throw new DBException("数据库主表ID[" + code + "]不存在");
        } else {
            List var4 = this.fieldService.queryFormFields(code, true);
            if (var4 != null && var4.size() != 0) {
                Map var5 = this.fieldService.queryFormData(var4, var3.getTableName(), id);
                if (var3.getTableType() == 2) {
                    String var6 = var3.getSubTableStr();
                    if (ConvertUtils.isNotEmpty(var6)) {
                        String[] var7 = var6.split(",");
                        String[] var8 = var7;
                        int var9 = var7.length;

                        for(int var10 = 0; var10 < var9; ++var10) {
                            String var11 = var8[var10];
                            OnlCgformHead var12 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var11));
                            if (var12 != null) {
                                List var13 = this.fieldService.queryFormFields(var12.getId(), false);
                                String var14 = "";
                                String var15 = null;
                                Iterator var16 = var13.iterator();

                                while(var16.hasNext()) {
                                    OnlCgformField var17 = (OnlCgformField)var16.next();
                                    if (!ConvertUtils.isEmpty(var17.getMainField())) {
                                        var14 = var17.getDbFieldName();
                                        String var18 = var17.getMainField();
                                        if (null == var5.get(var18)) {
                                            var15 = var5.get(var18.toUpperCase()).toString();
                                        } else {
                                            var15 = var5.get(var18).toString();
                                        }
                                    }
                                }

                                List var19 = this.fieldService.querySubFormData(var13, var11, var14, var15);
                                if (var19 != null && var19.size() != 0) {
                                    var5.put(var11, CgformUtil.m280d(var19));
                                } else {
                                    var5.put(var11, new String[0]);
                                }
                            }
                        }
                    }
                }

                return var5;
            } else {
                throw new DBException("找不到字段，请确认配置是否正确!");
            }
        }
    }

    @Transactional(rollbackFor = {Exception.class})
    public String editManyFormData(String code, JSONObject json) throws DBException, BusinessException {
        OnlCgformHead var3 = (OnlCgformHead)this.getById(code);
        if (var3 == null) {
            throw new DBException("数据库主表ID[" + code + "]不存在");
        } else {
            String var4 = "edit";
            this.executeEnhanceJava(var4, "start", var3, json);
            String var5 = var3.getTableName();
            if ("Y".equals(var3.getIsTree())) {
                this.fieldService.editTreeFormData(code, var5, json, var3.getTreeIdField(), var3.getTreeParentIdField());
            } else {
                this.fieldService.editFormData(code, var5, json, false);
            }

            if (var3.getTableType() == 2) {
                String var6 = var3.getSubTableStr();
                if (ConvertUtils.isNotEmpty(var6)) {
                    String[] var7 = var6.split(",");
                    String[] var8 = var7;
                    int var9 = var7.length;

                    for(int var10 = 0; var10 < var9; ++var10) {
                        String var11 = var8[var10];
                        OnlCgformHead var12 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var11));
                        if (var12 != null) {
                            List var13 = this.fieldService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var12.getId()));
                            String var14 = "";
                            String var15 = null;
                            Iterator var16 = var13.iterator();

                            while(var16.hasNext()) {
                                OnlCgformField var17 = (OnlCgformField)var16.next();
                                if (!ConvertUtils.isEmpty(var17.getMainField())) {
                                    var14 = var17.getDbFieldName();
                                    String var18 = var17.getMainField();
                                    if (json.get(var18.toLowerCase()) != null) {
                                        var15 = json.getString(var18.toLowerCase());
                                    }

                                    if (json.get(var18.toUpperCase()) != null) {
                                        var15 = json.getString(var18.toUpperCase());
                                    }
                                }
                            }

                            if (!ConvertUtils.isEmpty(var15)) {
                                this.fieldService.deleteAutoList(var11, var14, var15);
                                JSONArray var19 = json.getJSONArray(var11);
                                if (var19 != null && var19.size() != 0) {
                                    for(int var20 = 0; var20 < var19.size(); ++var20) {
                                        JSONObject var21 = var19.getJSONObject(var20);
                                        if (var15 != null) {
                                            var21.put(var14, var15);
                                        }

                                        this.fieldService.saveFormData(var13, var11, var21);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            this.executeEnhanceJava(var4, "end", var3, json);
            this.executeEnhanceSql(var4, code, json);
            return var5;
        }
    }

    private OnlCgformEnhanceJava m160a(String var1, String var2, String var3) {
        LambdaQueryWrapper<OnlCgformEnhanceJava> var4 = new LambdaQueryWrapper<OnlCgformEnhanceJava>();
        var4.eq(OnlCgformEnhanceJava::getActiveStatus, "1");
        var4.eq(OnlCgformEnhanceJava::getButtonCode, var1);
        var4.eq(OnlCgformEnhanceJava::getEvent, var2);
        var4.eq(OnlCgformEnhanceJava::getCgformHeadId, var3);
        return (OnlCgformEnhanceJava)this.onlCgformEnhanceJavaMapper.selectOne(var4);
    }

    private Object m171b(String var1, String var2, String var3) {
        LambdaQueryWrapper<OnlCgformEnhanceJava> var4 = new LambdaQueryWrapper<OnlCgformEnhanceJava>();
        var4.eq(OnlCgformEnhanceJava::getActiveStatus, "1");
        var4.eq(OnlCgformEnhanceJava::getButtonCode, var1);
        var4.eq(OnlCgformEnhanceJava::getEvent, var2);
        var4.eq(OnlCgformEnhanceJava::getCgformHeadId, var3);
        OnlCgformEnhanceJava var5 = (OnlCgformEnhanceJava)this.onlCgformEnhanceJavaMapper.selectOne(var4);
        Object var6 = this.m159a(var5);
        return var6;
    }

    private int m157a(JSONObject jSONObject, Object obj, String str, OnlCgformEnhanceJava onlCgformEnhanceJava) throws BusinessException {
        if (obj != null && (obj instanceof CgformEnhanceJavaInter)) {
            return ((CgformEnhanceJavaInter) obj).execute(str, jSONObject);
        }
        if (obj == null || !(obj instanceof CgformEnhanceHttpFormImpl)) {
            return 1;
        }
        return ((CgformEnhanceHttpFormImpl) obj).execute(str, jSONObject, onlCgformEnhanceJava);
    }

    @Override
    public int executeEnhanceJava(String buttonCode, String eventType, OnlCgformHead head, JSONObject json) throws BusinessException {
        OnlCgformEnhanceJava a = m160a(buttonCode, eventType, head.getId());
        return m157a(json, m159a(a), head.getTableName(), a);
    }

    @Override
    public void executeEnhanceExport(OnlCgformHead head, List<Map<String, Object>> dataList) throws BusinessException {
        executeEnhanceList(head, "export", dataList);
    }

    @Override
    public void executeEnhanceList(OnlCgformHead head, String buttonCode, List<Map<String, Object>> dataList) throws BusinessException {
        LambdaQueryWrapper<OnlCgformEnhanceJava> var4 = new LambdaQueryWrapper<OnlCgformEnhanceJava>();
        var4.eq(OnlCgformEnhanceJava::getActiveStatus, "1");
        var4.eq(OnlCgformEnhanceJava::getButtonCode, buttonCode);
        var4.eq(OnlCgformEnhanceJava::getCgformHeadId, head.getId());
        List var5 = this.onlCgformEnhanceJavaMapper.selectList(var4);
        if (var5 != null && var5.size() > 0) {
            Object var6 = this.m159a((OnlCgformEnhanceJava)var5.get(0));
            if (var6 != null && var6 instanceof CgformEnhanceJavaListInter) {
                CgformEnhanceJavaListInter var7 = (CgformEnhanceJavaListInter)var6;
                var7.execute(head.getTableName(), dataList);
            } else if (var6 != null && var6 instanceof com.data.modules.online.cgform.enhance.impl.http.CgformEnhanceHttpListImpl) {
                ((com.data.modules.online.cgform.enhance.impl.http.CgformEnhanceHttpListImpl)var6).execute(head.getTableName(), dataList, (OnlCgformEnhanceJava)var5.get(0));
            }
        }

    }

    private Object m159a(OnlCgformEnhanceJava onlCgformEnhanceJava) {
        if (onlCgformEnhanceJava == null) {
            return null;
        }
        String cgJavaType = onlCgformEnhanceJava.getCgJavaType();
        String cgJavaValue = onlCgformEnhanceJava.getCgJavaValue();
        if (!ConvertUtils.isNotEmpty(cgJavaValue)) {
            return null;
        }
        if ("class".equals(cgJavaType)) {
            try {
                return MyClassLoader.getClassByScn(cgJavaValue).newInstance();
            } catch (InstantiationException e) {
                f213a.error(e.getMessage(), e);
                return null;
            } catch (IllegalAccessException e2) {
                f213a.error(e2.getMessage(), e2);
                return null;
            }
        } else if ("spring".equals(cgJavaType)) {
            return SpringContextUtils.getBean(cgJavaValue);
        } else {
            if ("http".equals(cgJavaType)) {
                return m172b(onlCgformEnhanceJava);
            }
            return null;
        }
    }

    private Object m172b(OnlCgformEnhanceJava onlCgformEnhanceJava) {
        String buttonCode = onlCgformEnhanceJava.getButtonCode();
        char c = 65535;
        switch (buttonCode.hashCode()) {
            case -1335458389:
                if (buttonCode.equals(CgformConstant.ENHANCE_JAVA_BUTTON_DELETE)) {
                    c = 2;
                    break;
                }
                break;
            case -1289153612:
                if (buttonCode.equals("export")) {
                    c = 4;
                    break;
                }
                break;
            case -1184795739:
                if (buttonCode.equals("import")) {
                    c = 3;
                    break;
                }
                break;
            case 96417:
                if (buttonCode.equals(CgformConstant.ENHANCE_JAVA_BUTTON_ADD)) {
                    c = 0;
                    break;
                }
                break;
            case 3108362:
                if (buttonCode.equals(CgformConstant.ENHANCE_JAVA_BUTTON_EDIT)) {
                    c = 1;
                    break;
                }
                break;
            case 107944136:
                if (buttonCode.equals("query")) {
                    c = 5;
                    break;
                }
                break;
        }
        switch (c) {
            case 0:
            case 1:
            case 2:
            case 3:
                return this.cgformEnhanceJavaHttp;
            case 4:
            case 5:
                return this.cgformEnhanceJavaListHttp;
            default:
                return null;
        }
    }

    private OnlCgformEnhanceSql m174b(String var1, String var2) {
        LambdaQueryWrapper<OnlCgformEnhanceSql> var3 = new LambdaQueryWrapper<OnlCgformEnhanceSql>();
        var3.eq(OnlCgformEnhanceSql::getButtonCode, var1);
        var3.eq(OnlCgformEnhanceSql::getCgformHeadId, var2);
        OnlCgformEnhanceSql var4 = (OnlCgformEnhanceSql)this.onlCgformEnhanceSqlMapper.selectOne(var3);
        return var4;
    }

    private void m163a(JSONObject jSONObject, OnlCgformEnhanceSql onlCgformEnhanceSql) {
        if (onlCgformEnhanceSql != null && ConvertUtils.isNotEmpty(onlCgformEnhanceSql.getCgbSql())) {
            String[] split = CgformUtil.m226a(onlCgformEnhanceSql.getCgbSql(), jSONObject).split(";");
            for (String str : split) {
                if (str != null && !str.toLowerCase().trim().equals("")) {
                    this.baseMapper.executeDDL(str);
                }
            }
        }
    }

    @Override
    public void executeEnhanceSql(String buttonCode, String formId, JSONObject json) {
        m163a(json, m174b(buttonCode, formId));
    }

    @Override
    public void executeCustomerButton(String buttonCode, String formId, String dataId) throws BusinessException {
        OnlCgformHead onlCgformHead = (OnlCgformHead) getById(formId);
        if (onlCgformHead == null) {
            throw new BusinessException("未找到表配置信息");
        }
        OnlCgformEnhanceJava a = m160a(buttonCode, CgformUtil.f279ao, formId);
        OnlCgformEnhanceJava a2 = m160a(buttonCode, "end", formId);
        Object a3 = m159a(a);
        Object a4 = m159a(a2);
        OnlCgformEnhanceSql b = m174b(buttonCode, formId);
        String tableName = onlCgformHead.getTableName();
        for (String str : dataId.split(CgformUtil.f231E)) {
            JSONObject parseObject = JSONObject.parseObject(JSON.toJSONString(this.baseMapper.queryOneByTableNameAndId(CgformUtil.m285f(onlCgformHead.getTableName()), str)));
            m157a(parseObject, a3, tableName, a);
            m163a(parseObject, b);
            m157a(parseObject, a4, tableName, a2);
        }
    }

    @Override
    public java.util.List<com.data.modules.online.cgform.entity.OnlCgformButton> queryValidButtonList(java.lang.String r4) {
        /*
            r3 = this;
            com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper r0 = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
            void r1 = r0.<init>()
            java.lang.Object r1 = r0.eq(r1, r4)
            java.lang.String r2 = "1"
            java.lang.Object r1 = r0.eq(r1, r2)
            r0.orderByAsc(r1)
            com.data.modules.online.cgform.mapper.OnlCgformButtonMapper r1 = r3.onlCgformButtonMapper
            java.util.List r0 = r1.selectList(r0)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.queryValidButtonList(java.lang.String):java.util.List");
    }

    @Override
    public OnlCgformEnhanceJs queryEnhanceJs(String formId, String cgJsType) {
        LambdaQueryWrapper<OnlCgformEnhanceJs> var3 = new LambdaQueryWrapper<OnlCgformEnhanceJs>();
        var3.eq(OnlCgformEnhanceJs::getCgformHeadId, formId);
        var3.eq(OnlCgformEnhanceJs::getCgJsType, cgJsType);
        return this.onlCgformEnhanceJsMapper.selectOne(var3);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void deleteOneTableInfo(String formId, String dataId) throws BusinessException {
        OnlCgformHead onlCgformHead = (OnlCgformHead) getById(formId);
        if (onlCgformHead == null) {
            throw new BusinessException("未找到表配置信息");
        }
        String f = CgformUtil.m285f(onlCgformHead.getTableName());
        Map<String, Object> queryOneByTableNameAndId = this.baseMapper.queryOneByTableNameAndId(f, dataId);
        if (queryOneByTableNameAndId == null) {
            throw new BusinessException("未找到数据信息");
        }
        JSONObject parseObject = JSONObject.parseObject(JSON.toJSONString(CgformUtil.m242a(queryOneByTableNameAndId)));
        executeEnhanceJava(CgformConstant.ENHANCE_JAVA_BUTTON_DELETE, CgformUtil.f279ao, onlCgformHead, parseObject);
        updateParentNode(onlCgformHead, dataId);
        if (onlCgformHead.getTableType().intValue() == 2) {
            this.fieldService.deleteAutoListMainAndSub(onlCgformHead, dataId);
        } else {
            this.baseMapper.deleteOne("delete from " + f + " where id = '" + dataId + CgformUtil.f229C);
        }
        executeEnhanceSql(CgformConstant.ENHANCE_JAVA_BUTTON_DELETE, formId, parseObject);
        executeEnhanceJava(CgformConstant.ENHANCE_JAVA_BUTTON_DELETE, "end", onlCgformHead, parseObject);
    }

    @Override
    @java.lang.Deprecated
    public com.alibaba.fastjson.JSONObject queryFormItem(com.data.modules.online.cgform.entity.OnlCgformHead r13, java.lang.String r14) {
        /*
        // Method dump skipped, instructions count: 319
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.queryFormItem(com.data.modules.online.cgform.entity.OnlCgformHead, java.lang.String):com.alibaba.fastjson.JSONObject");
    }

    @Override
    public List<String> generateCode(OnlGenerateModel model) throws Exception {
        TableVo var2 = new TableVo();
        var2.setEntityName(model.getEntityName());
        var2.setEntityPackage(model.getEntityPackage());
        var2.setFtlDescription(model.getFtlDescription());
        var2.setTableName(model.getTableName());
        var2.setSearchFieldNum(-1);
        ArrayList var3 = new ArrayList();
        ArrayList var4 = new ArrayList();
        this.m161a((String)model.getCode(), (List)var3, (List)var4);
        OnlCgformHead var5 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getId, model.getCode()));
        HashMap var6 = new HashMap();
        var6.put("scroll", var5.getScroll() == null ? "0" : var5.getScroll().toString());
        String var7 = var5.getFormTemplate();
        if (ConvertUtils.isEmpty(var7)) {
            var2.setFieldRowNum(1);
        } else {
            var2.setFieldRowNum(Integer.parseInt(var7));
        }

        if ("Y".equals(var5.getIsTree())) {
            var6.put("pidField", var5.getTreeParentIdField());
            var6.put("hasChildren", var5.getTreeIdField());
            var6.put("textField", var5.getTreeFieldname());
        }

        var2.setExtendParams(var6);
        CgformEnum var8 = CgformEnum.getCgformEnumByConfig(model.getJspMode());
        Object var9 = (new CodeGenerateOne(var2, var3, var4)).generateCodeFile(model.getProjectPath(), var8.getTemplatePath(), var8.getStylePath());
        if (var9 == null || ((List)var9).size() == 0) {
            var9 = new ArrayList();
            ((List)var9).add(" :::::: 生成失败ERROR提醒 :::::: ");
            ((List)var9).add("1.未找到代码生成器模板，请确认路径是否含有中文或特殊字符！");
            ((List)var9).add("2.如果是JAR包运行，请参考此文档 http://doc.jeecg.com/2043922");
        }

        return (List)var9;
    }


    @Override
    public List<String> generateOneToMany(OnlGenerateModel model) throws Exception {
        MainTableVo var2 = new MainTableVo();
        var2.setEntityName(model.getEntityName());
        var2.setEntityPackage(model.getEntityPackage());
        var2.setFtlDescription(model.getFtlDescription());
        var2.setTableName(model.getTableName());
        OnlCgformHead var3 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getId, model.getCode()));
        String var4 = var3.getFormTemplate();
        if (ConvertUtils.isEmpty(var4)) {
            var2.setFieldRowNum(1);
        } else {
            var2.setFieldRowNum(Integer.parseInt(var4));
        }

        ArrayList var5 = new ArrayList();
        ArrayList var6 = new ArrayList();
        this.m161a((String)model.getCode(), (List)var5, (List)var6);
        List var7 = model.getSubList();
        ArrayList var8 = new ArrayList();
        Iterator var9 = var7.iterator();

        while(var9.hasNext()) {
            OnlGenerateModel var10 = (OnlGenerateModel)var9.next();
            OnlCgformHead var11 = (OnlCgformHead)((OnlCgformHeadMapper)this.baseMapper).selectOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var10.getTableName()));
            if (var11 != null) {
                SubTableVo var12 = new SubTableVo();
                var12.setEntityName(var10.getEntityName());
                var12.setEntityPackage(model.getEntityPackage());
                var12.setTableName(var10.getTableName());
                var12.setFtlDescription(var10.getFtlDescription());
                Integer var13 = var11.getRelationType();
                var12.setForeignRelationType(var13 == 1 ? "1" : "0");
                ArrayList var14 = new ArrayList();
                ArrayList var15 = new ArrayList();
                OnlCgformField var16 = this.m161a((String)var11.getId(), (List)var14, (List)var15);
                if (var16 != null) {
                    var12.setOriginalForeignKeys(new String[]{var16.getDbFieldName()});
                    var12.setForeignKeys(new String[]{var16.getDbFieldName()});
                    var12.setColums(var14);
                    var12.setOriginalColumns(var15);
                    var8.add(var12);
                }
            }
        }

        CgformEnum var17 = CgformEnum.getCgformEnumByConfig(model.getJspMode());
        List var18 = (new CodeGenerateOneToMany(var2, var5, var6, var8)).generateCodeFile(model.getProjectPath(), var17.getTemplatePath(), var17.getStylePath());
        return var18;
    }

    private com.data.modules.online.cgform.entity.OnlCgformField m161a(String var1, List<ColumnVo> var2, List<ColumnVo> var3) {
        LambdaQueryWrapper<OnlCgformField> var4 = new LambdaQueryWrapper();
        var4.eq(OnlCgformField::getCgformHeadId, var1);
        var4.orderByAsc(OnlCgformField::getOrderNum);
        List var5 = this.fieldService.list(var4);
        OnlCgformField var6 = null;
        Iterator var7 = var5.iterator();

        while (true) {
            OnlCgformField var8;
            ColumnVo var9;
            do {
                if (!var7.hasNext()) {
                    return var6;
                }

                var8 = (OnlCgformField) var7.next();
                if (ConvertUtils.isNotEmpty(var8.getMainTable())) {
                    var6 = var8;
                }

                var9 = new ColumnVo();
                var9.setFieldLength(var8.getFieldLength());
                var9.setFieldHref(var8.getFieldHref());
                var9.setFieldValidType(var8.getFieldValidType());
                var9.setFieldDefault(var8.getDbDefaultVal());
                var9.setFieldShowType(var8.getFieldShowType());
                var9.setFieldOrderNum(var8.getOrderNum());
                var9.setIsKey(var8.getDbIsKey() == 1 ? "Y" : "N");
                var9.setIsShow(var8.getIsShowForm() == 1 ? "Y" : "N");
                var9.setIsShowList(var8.getIsShowList() == 1 ? "Y" : "N");
                var9.setIsQuery(var8.getIsQuery() == 1 ? "Y" : "N");
                var9.setQueryMode(var8.getQueryMode());
                var9.setDictField(var8.getDictField());
                if (ConvertUtils.isNotEmpty(var8.getDictTable()) && var8.getDictTable().indexOf("where") > 0) {
                    var9.setDictTable(var8.getDictTable().split("where")[0].trim());
                } else {
                    var9.setDictTable(var8.getDictTable());
                }

                var9.setDictText(var8.getDictText());
                var9.setFieldDbName(var8.getDbFieldName());
                var9.setFieldName(ConvertUtils.camelName(var8.getDbFieldName()));
                var9.setFiledComment(var8.getDbFieldTxt());
                var9.setFieldDbType(var8.getDbType());
                var9.setFieldType(this.m173b(var8.getDbType()));
                var9.setClassType(var8.getFieldShowType());
                var9.setClassType_row(var8.getFieldShowType());
                if (var8.getDbIsNull() != 0 && !"*".equals(var8.getFieldValidType()) && !"1".equals(var8.getFieldMustInput())) {
                    var9.setNullable("Y");
                } else {
                    var9.setNullable("N");
                }

                if ("switch".equals(var8.getFieldShowType())) {
                    if (ConvertUtils.isNotEmpty(var8.getFieldExtendJson())) {
                        var9.setDictField(var8.getFieldExtendJson());
                    } else {
                        var9.setDictField("is_open");
                    }
                }

                HashMap var10 = new HashMap();
                JSONObject var11;
                if (StringUtils.isNotBlank(var8.getFieldExtendJson())) {
                    try {
                        var11 = JSONObject.parseObject(var8.getFieldExtendJson());
                        if (var11 != null) {
                            var10.putAll(var11.getInnerMap());
                        }
                    } catch (JSONException var13) {
                    }
                }

                var9.setExtendParams(var10);
                if ("popup".equals(var8.getFieldShowType())) {
                    boolean var14 = true;
                    Object var12 = var10.get("popupMulti");
                    if (var12 != null) {
                        var14 = (Boolean) var12;
                    }

                    var10.put("popupMulti", var14);
                }

                var9.setSort("1".equals(var8.getSortFlag()) ? "Y" : "N");
                var9.setReadonly(Integer.valueOf(1).equals(var8.getIsReadOnly()) ? "Y" : "N");
                if (ConvertUtils.isNotEmpty(var8.getFieldDefaultValue()) && !var8.getFieldDefaultValue().trim().startsWith("${") && !var8.getFieldDefaultValue().trim().startsWith("#{") && !var8.getFieldDefaultValue().trim().startsWith("{{")) {
                    var9.setDefaultVal(var8.getFieldDefaultValue());
                }

                if (("file".equals(var8.getFieldShowType()) || "image".equals(var8.getFieldShowType())) && ConvertUtils.isNotEmpty(var8.getFieldExtendJson())) {
                    var11 = JSONObject.parseObject(var8.getFieldExtendJson());
                    if (ConvertUtils.isNotEmpty(var11.getString("uploadnum"))) {
                        var9.setUploadnum(var11.getString("uploadnum"));
                    }
                }

                var3.add(var9);
            } while (var8.getIsShowForm() != 1 && var8.getIsShowList() != 1 && var8.getIsQuery() != 1);

            var2.add(var9);
        }
    }
    private String m173b(String str) {
        String lowerCase = str.toLowerCase();
        if (lowerCase.indexOf("int") >= 0) {
            return "java.lang.Integer";
        }
        if (lowerCase.indexOf("double") >= 0) {
            return "java.lang.Double";
        }
        if (lowerCase.indexOf(DataBaseConst.f470e) >= 0) {
            return "java.math.BigDecimal";
        }
        if (lowerCase.indexOf(OnlFormShowType.f320d) >= 0) {
            return "java.util.Date";
        }
        return "java.lang.String";
    }


    @Override
    public void addCrazyFormData(java.lang.String r14, com.alibaba.fastjson.JSONObject r15) throws com.data.modules.online.config.exception.DBException, java.io.UnsupportedEncodingException {
        /*
        // Method dump skipped, instructions count: 299
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.addCrazyFormData(java.lang.String, com.alibaba.fastjson.JSONObject):void");
    }


    @Override
    public void editCrazyFormData(java.lang.String r14, com.alibaba.fastjson.JSONObject r15) throws com.data.modules.online.config.exception.DBException, java.io.UnsupportedEncodingException {
        /*
        // Method dump skipped, instructions count: 320
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.editCrazyFormData(java.lang.String, com.alibaba.fastjson.JSONObject):void");
    }

    @Override
    public Integer getMaxCopyVersion(String physicId) {
        Integer maxCopyVersion = this.baseMapper.getMaxCopyVersion(physicId);
        return Integer.valueOf(maxCopyVersion == null ? 0 : maxCopyVersion.intValue());
    }

    @Override
    public void copyOnlineTableConfig(OnlCgformHead physicTable) throws Exception {
        String var2 = physicTable.getId();
        OnlCgformHead var3 = new OnlCgformHead();
        String var4 = UUIDGenerator.generate();
        var3.setId(var4);
        var3.setPhysicId(var2);
        var3.setCopyType(1);
        var3.setCopyVersion(physicTable.getTableVersion());
        var3.setTableVersion(1);
        var3.setTableName(this.c(var2, physicTable.getTableName()));
        var3.setTableTxt(physicTable.getTableTxt());
        var3.setFormCategory(physicTable.getFormCategory());
        var3.setFormTemplate(physicTable.getFormTemplate());
        var3.setFormTemplateMobile(physicTable.getFormTemplateMobile());
        var3.setIdSequence(physicTable.getIdSequence());
        var3.setIdType(physicTable.getIdType());
        var3.setIsCheckbox(physicTable.getIsCheckbox());
        var3.setIsPage(physicTable.getIsPage());
        var3.setIsTree(physicTable.getIsTree());
        var3.setQueryMode(physicTable.getQueryMode());
        var3.setTableType(1);
        var3.setIsDbSynch("N");
        var3.setIsDesForm(physicTable.getIsDesForm());
        var3.setDesFormCode(physicTable.getDesFormCode());
        var3.setTreeParentIdField(physicTable.getTreeParentIdField());
        var3.setTreeFieldname(physicTable.getTreeFieldname());
        var3.setTreeIdField(physicTable.getTreeIdField());
        var3.setRelationType((Integer)null);
        var3.setTabOrderNum((Integer)null);
        var3.setSubTableStr((String)null);
        var3.setThemeTemplate(physicTable.getThemeTemplate());
        var3.setScroll(physicTable.getScroll());
        var3.setExtConfigJson(physicTable.getExtConfigJson());
        List var5 = this.fieldService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var2));
        Iterator var6 = var5.iterator();

        while(var6.hasNext()) {
            OnlCgformField var7 = (OnlCgformField)var6.next();
            OnlCgformField var8 = new OnlCgformField();
            var8.setCgformHeadId(var4);
            this.a(var7, var8);
            this.fieldService.save(var8);
        }

        ((OnlCgformHeadMapper)this.baseMapper).insert(var3);
    }

    private void a(OnlCgformField var1, OnlCgformField var2) {
        var2.setDbDefaultVal(var1.getDbDefaultVal());
        var2.setDbFieldName(var1.getDbFieldName());
        var2.setDbFieldNameOld(var1.getDbFieldNameOld());
        var2.setDbFieldTxt(var1.getDbFieldTxt());
        var2.setDbIsKey(var1.getDbIsKey());
        var2.setDbIsNull(var1.getDbIsNull());
        var2.setDbLength(var1.getDbLength());
        var2.setDbPointLength(var1.getDbPointLength());
        var2.setDbType(var1.getDbType());
        var2.setDictField(var1.getDictField());
        var2.setDictTable(var1.getDictTable());
        var2.setDictText(var1.getDictText());
        var2.setFieldExtendJson(var1.getFieldExtendJson());
        var2.setFieldHref(var1.getFieldHref());
        var2.setFieldLength(var1.getFieldLength());
        var2.setFieldMustInput(var1.getFieldMustInput());
        var2.setFieldShowType(var1.getFieldShowType());
        var2.setFieldValidType(var1.getFieldValidType());
        var2.setFieldDefaultValue(var1.getFieldDefaultValue());
        var2.setIsQuery(var1.getIsQuery());
        var2.setIsShowForm(var1.getIsShowForm());
        var2.setIsShowList(var1.getIsShowList());
        var2.setMainField((String)null);
        var2.setMainTable((String)null);
        var2.setOrderNum(var1.getOrderNum());
        var2.setQueryMode(var1.getQueryMode());
        var2.setIsReadOnly(var1.getIsReadOnly());
        var2.setSortFlag(var1.getSortFlag());
        var2.setQueryDefVal(var1.getQueryDefVal());
        var2.setQueryConfigFlag(var1.getQueryConfigFlag());
        var2.setQueryDictField(var1.getQueryDictField());
        var2.setQueryDictTable(var1.getQueryDictTable());
        var2.setQueryDictText(var1.getQueryDictText());
        var2.setQueryMustInput(var1.getQueryMustInput());
        var2.setQueryShowType(var1.getQueryShowType());
        var2.setQueryValidType(var1.getQueryValidType());
        var2.setConverter(var1.getConverter());
    }

    private String c(String var1, String var2) {
        List var3 = ((OnlCgformHeadMapper)this.baseMapper).queryAllCopyTableName(var1);
        int var4 = 0;
        if (var3 != null || var3.size() > 0) {
            for(int var5 = 0; var5 < var3.size(); ++var5) {
                String var6 = (String)var3.get(var5);
                int var7 = Integer.parseInt(var6.split("\\$")[1]);
                if (var7 > var4) {
                    var4 = var7;
                }
            }
        }

        StringBuilder var10000 = (new StringBuilder()).append(var2).append("$");
        ++var4;
        return var10000.append(var4).toString();
    }

    @Override
    public void initCopyState(List<OnlCgformHead> headList) {
        List<String> queryCopyPhysicId = this.baseMapper.queryCopyPhysicId();
        for (OnlCgformHead onlCgformHead : headList) {
            if (queryCopyPhysicId.contains(onlCgformHead.getId())) {
                onlCgformHead.setHascopy(1);
            } else {
                onlCgformHead.setHascopy(0);
            }
        }
    }

    @Override
    public void deleteBatch(String ids, String flag) {
        String[] split = ids.split(CgformUtil.f231E);
        if ("1".equals(flag)) {
            for (String str : split) {
                try {
                    deleteRecordAndTable(str);
                } catch (DBException e) {
                    e.printStackTrace();
                } catch (SQLException e2) {
                    e2.printStackTrace();
                }
            }
            return;
        }
        removeByIds(Arrays.asList(split));
    }

    @Override
    public void updateParentNode(OnlCgformHead head, String dataId) {
        String obj;
        if ("Y".equals(head.getIsTree())) {
            String f = CgformUtil.m285f(head.getTableName());
            String treeParentIdField = head.getTreeParentIdField();
            Map<String, Object> queryOneByTableNameAndId = this.baseMapper.queryOneByTableNameAndId(f, dataId);
            if (queryOneByTableNameAndId.get(treeParentIdField) == null || "0".equals(queryOneByTableNameAndId.get(treeParentIdField))) {
                obj = (queryOneByTableNameAndId.get(treeParentIdField.toUpperCase()) == null || "0".equals(queryOneByTableNameAndId.get(treeParentIdField.toUpperCase()))) ? null : queryOneByTableNameAndId.get(treeParentIdField.toUpperCase()).toString();
            } else {
                obj = queryOneByTableNameAndId.get(treeParentIdField).toString();
            }
            if (obj != null && this.baseMapper.queryChildNode(f, treeParentIdField, obj).intValue() == 1) {
                this.fieldService.updateTreeNodeNoChild(f, head.getTreeIdField(), obj);
            }
        }
    }


    private void m176b(com.data.modules.online.cgform.entity.OnlCgformHead r12, java.util.List<com.data.modules.online.cgform.entity.OnlCgformField> r13) {
        /*
        // Method dump skipped, instructions count: 385
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.m176b(com.data.modules.online.cgform.entity.OnlCgformHead, java.util.List):void");
    }

    private void m175b(String str, List<OnlCgformField> list, List<OnlCgformField> list2) {
        OnlCgformField onlCgformField = null;
        boolean z = true;
        OnlCgformField onlCgformField2 = null;
        for (OnlCgformField onlCgformField3 : list) {
            if (!str.equals(onlCgformField3.getDbFieldName())) {
                onlCgformField3 = onlCgformField2;
            }
            onlCgformField2 = onlCgformField3;
        }
        for (OnlCgformField onlCgformField4 : list2) {
            if (!str.equals(onlCgformField4.getDbFieldName())) {
                onlCgformField4 = onlCgformField;
            }
            onlCgformField = onlCgformField4;
        }
        if (!(onlCgformField2 == null || onlCgformField == null)) {
            boolean z2 = false;
            if (!onlCgformField2.getDbType().equals(onlCgformField.getDbType())) {
                onlCgformField.setDbType(onlCgformField2.getDbType());
                z2 = true;
            }
            if (!onlCgformField2.getDbDefaultVal().equals(onlCgformField.getDbDefaultVal())) {
                onlCgformField.setDbDefaultVal(onlCgformField2.getDbDefaultVal());
                z2 = true;
            }
            if (onlCgformField2.getDbLength() != onlCgformField.getDbLength()) {
                onlCgformField.setDbLength(onlCgformField2.getDbLength());
                z2 = true;
            }
            if (onlCgformField2.getDbIsNull() != onlCgformField.getDbIsNull()) {
                onlCgformField.setDbIsNull(onlCgformField2.getDbIsNull());
            } else {
                z = z2;
            }
            if (z) {
                this.fieldService.updateById(onlCgformField);
            }
        }
    }

    private void m167a(OnlCgformField onlCgformField, OnlCgformField onlCgformField2) {
        onlCgformField2.setDbDefaultVal(onlCgformField.getDbDefaultVal());
        onlCgformField2.setDbFieldName(onlCgformField.getDbFieldName());
        onlCgformField2.setDbFieldNameOld(onlCgformField.getDbFieldNameOld());
        onlCgformField2.setDbFieldTxt(onlCgformField.getDbFieldTxt());
        onlCgformField2.setDbIsKey(onlCgformField.getDbIsKey());
        onlCgformField2.setDbIsNull(onlCgformField.getDbIsNull());
        onlCgformField2.setDbLength(onlCgformField.getDbLength());
        onlCgformField2.setDbPointLength(onlCgformField.getDbPointLength());
        onlCgformField2.setDbType(onlCgformField.getDbType());
        onlCgformField2.setDictField(onlCgformField.getDictField());
        onlCgformField2.setDictTable(onlCgformField.getDictTable());
        onlCgformField2.setDictText(onlCgformField.getDictText());
        onlCgformField2.setFieldExtendJson(onlCgformField.getFieldExtendJson());
        onlCgformField2.setFieldHref(onlCgformField.getFieldHref());
        onlCgformField2.setFieldLength(onlCgformField.getFieldLength());
        onlCgformField2.setFieldMustInput(onlCgformField.getFieldMustInput());
        onlCgformField2.setFieldShowType(onlCgformField.getFieldShowType());
        onlCgformField2.setFieldValidType(onlCgformField.getFieldValidType());
        onlCgformField2.setFieldDefaultValue(onlCgformField.getFieldDefaultValue());
        onlCgformField2.setIsQuery(onlCgformField.getIsQuery());
        onlCgformField2.setIsShowForm(onlCgformField.getIsShowForm());
        onlCgformField2.setIsShowList(onlCgformField.getIsShowList());
        onlCgformField2.setMainField(null);
        onlCgformField2.setMainTable(null);
        onlCgformField2.setOrderNum(onlCgformField.getOrderNum());
        onlCgformField2.setQueryMode(onlCgformField.getQueryMode());
        onlCgformField2.setIsReadOnly(onlCgformField.getIsReadOnly());
        onlCgformField2.setSortFlag(onlCgformField.getSortFlag());
        onlCgformField2.setQueryDefVal(onlCgformField.getQueryDefVal());
        onlCgformField2.setQueryConfigFlag(onlCgformField.getQueryConfigFlag());
        onlCgformField2.setQueryDictField(onlCgformField.getQueryDictField());
        onlCgformField2.setQueryDictTable(onlCgformField.getQueryDictTable());
        onlCgformField2.setQueryDictText(onlCgformField.getQueryDictText());
        onlCgformField2.setQueryMustInput(onlCgformField.getQueryMustInput());
        onlCgformField2.setQueryShowType(onlCgformField.getQueryShowType());
        onlCgformField2.setQueryValidType(onlCgformField.getQueryValidType());
        onlCgformField2.setConverter(onlCgformField.getConverter());
    }

    private void m166a(OnlCgformField onlCgformField) {
        if (DataBaseConst.f475j.equals(onlCgformField.getDbType()) || "Blob".equals(onlCgformField.getDbType())) {
            onlCgformField.setDbLength(0);
            onlCgformField.setDbPointLength(0);
        }
    }

    private String m177c(String str, String str2) {
        int i = 0;
        List<String> queryAllCopyTableName = this.baseMapper.queryAllCopyTableName(str);
        if (queryAllCopyTableName != null || queryAllCopyTableName.size() > 0) {
            for (int i2 = 0; i2 < queryAllCopyTableName.size(); i2++) {
                i = Integer.parseInt(queryAllCopyTableName.get(i2).split("\\$")[1]);
                if (i <= i) {
                    i = i;
                }
            }
            i = i;
        }
        return str2 + CgformUtil.f311v + (i + 1);
    }

    @Override
    @Transactional(rollbackFor = {java.lang.Exception.class})
    public java.lang.String deleteDataByCode(java.lang.String r5, java.lang.String r6) {
        /*
        // Method dump skipped, instructions count: 115
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.deleteDataByCode(java.lang.String, java.lang.String):java.lang.String");
    }

    private void m162a(com.alibaba.fastjson.JSONObject r8, java.lang.String r9, java.lang.String r10) throws java.lang.Exception {
        /*
        // Method dump skipped, instructions count: 224
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.m162a(com.alibaba.fastjson.JSONObject, java.lang.String, java.lang.String):void");
    }


    @Override
public com.alibaba.fastjson.JSONObject queryAllDataByTableNameForDesform(java.lang.String r9, java.lang.String r10) throws com.data.modules.online.config.exception.DBException {
        /*
        // Method dump skipped, instructions count: 196
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.service.p013a.OnlCgformHeadServiceImpl.queryAllDataByTableNameForDesform(java.lang.String, java.lang.String):com.alibaba.fastjson.JSONObject");
    }

    private DataBaseConfig getOnlineDataBaseConfig() {
        if (ConvertUtils.isEmpty(this.onlineDatasource)) {
            return this.dataBaseConfig;
        }
        DataSourceProperty dataSourceProperty = CommonUtils.getDataSourceProperty(this.onlineDatasource);
        if (dataSourceProperty == null) {
            f213a.error("jeecg.online.datasource配置错误,获取不到数据源返回master");
            return this.dataBaseConfig;
        }
        DataBaseConfig bVar = new DataBaseConfig();
        bVar.setDriverClassName(dataSourceProperty.getDriverClassName());
        bVar.setPassword(dataSourceProperty.getPassword());
        bVar.setUsername(dataSourceProperty.getUsername());
        bVar.setUrl(dataSourceProperty.getUrl());
        bVar.setDmDataBaseConfig(new DmDataBaseConfig());
        return bVar;
    }
}
